package com.ryl.yomall.product.api;

import com.ryl.yomall.model.product.*;
import com.ryl.yomall.product.mapper.SkuAttrValueMapper;
import com.ryl.yomall.product.service.ManageService;
import com.ryl.yomall.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Date 20:32
 * @Author ryl
 */


@RequestMapping("api/product")
@RestController
public class ProductApiController {
    @Autowired
    private ProductService productService;
    @Autowired
    private ManageService manageService;
    @Autowired
    private SkuAttrValueMapper skuAttrValueMapper;

    /**
     * 对于商品详情页,我们要查三级分类
     */
    @GetMapping("/inner/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id){
        return productService.getBaseCategoryView(category3Id);
    }
    /**
     * 查商品的的信息也就是skuInfo
     */
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) throws InterruptedException {
        return productService.getSkuInfo(skuId);
    }
    /**
     * 获取商品的价格
     */
    @GetMapping("/inner/getPrice/{skuId}")
    public BigDecimal getPrice (@PathVariable Long skuId){
      return  productService.getPrice(skuId);
    }
    /**
     * 查询当前商品spu对应的销售属性,和销售属性值集合,并sku_id 选中
     */
    @GetMapping("/inner/getSpuSaleAttrAndChecked/{spuId}/{skuId}")
    public List<SpuSaleAttr> getSpuSaleAttrAndChecked(@PathVariable Long spuId,@PathVariable Long skuId){
      return  productService.getSpuSaleAttrAndChecked(spuId,skuId);
    }
    /**
     * 销售属性值id的组合,对应的sku数据
     */
    @GetMapping("/inner/getSaleAttrValuesBySpu/{spuId}")
    public Map getSaleAttrValuesBySpu(@PathVariable Long spuId){

        return productService.getSaleAttrValuesBySpu(spuId);
    }
    /**
     * 获取首页的三级分类
     */
    @GetMapping("/inner/getBaseCategoryViewList")
    public List<BaseCategoryView> getBaseCategoryViewList(){
       return  productService.getBaseCategoryViewList();
    }

    @GetMapping("/inner/baseTrademark/{id}")
    public BaseTrademark getBaseTrademark(@PathVariable Long id){
        return manageService.getBaseTrademark ( id );
    }
    /**
     * 查询平台属性和平台属性值
     */
    @GetMapping("/inner/getBaseAttrInfoAndBaseAttrValue/{skuId}")
    public List<SkuAttrValue> getBaseAttrInfoAndBaseAttrValue(@PathVariable Long skuId){
      return skuAttrValueMapper.getBaseAttrInfoAndBaseAttrValue(skuId);
    }


}
